home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / Zoners Half-Life Tools / hlrad / nomatrix.cpp < prev    next >
C/C++ Source or Header  |  2002-12-09  |  4KB  |  128 lines

  1. #include "qrad.h"
  2.  
  3. // =====================================================================================
  4. //  CheckVisBit
  5. // =====================================================================================
  6. #ifdef HLRAD_HULLU
  7. static bool     CheckVisBitNoVismatrix(unsigned patchnum1, unsigned patchnum2, vec3_t &transparency_out)
  8. #else
  9. static bool     CheckVisBitNoVismatrix(unsigned patchnum1, unsigned patchnum2)
  10. #endif
  11. {
  12. #ifdef HLRAD_HULLU
  13.     // This fix was in vismatrix and sparse methods but not in nomatrix
  14.     // Without this nomatrix causes SwapTransfers output lots of errors
  15.     if (patchnum1 > patchnum2)
  16.     {
  17.         const unsigned a = patchnum1;
  18.         const unsigned b = patchnum2;
  19.         patchnum1 = b;
  20.         patchnum2 = a;
  21.     }
  22.     
  23.     if (patchnum1 > g_num_patches)
  24.     {
  25.         Warning("in CheckVisBit(), patchnum1 > num_patches");
  26.     }
  27.     if (patchnum2 > g_num_patches)
  28.     {
  29.         Warning("in CheckVisBit(), patchnum2 > num_patches");
  30.     }
  31. #endif
  32.     
  33.     patch_t*        patch = &g_patches[patchnum1];
  34.     patch_t*        patch2 = &g_patches[patchnum2];
  35.  
  36. #ifdef HLRAD_HULLU
  37.     VectorFill(transparency_out, 1.0);
  38. #endif
  39.  
  40.     // if emitter is behind that face plane, skip all patches
  41.  
  42.     if (patch2)
  43.     {
  44.         const dplane_t* plane2 = getPlaneFromFaceNumber(patch2->faceNumber);
  45.  
  46.         if (DotProduct(patch->origin, plane2->normal) > (PatchPlaneDist(patch2) + MINIMUM_PATCH_DISTANCE))
  47.         {
  48.             // we need to do a real test
  49.  
  50.             const dplane_t* plane = getPlaneFromFaceNumber(patch->faceNumber);
  51.  
  52. #ifdef HLRAD_HULLU
  53.             vec3_t transparency = {1.0,1.0,1.0};
  54. #endif
  55.  
  56.             // check vis between patch and patch2
  57.             //  if v2 is not behind light plane
  58.             //  && v2 is visible from v1
  59.             if (
  60.                 (DotProduct(patch2->origin, plane->normal) > (PatchPlaneDist(patch) + MINIMUM_PATCH_DISTANCE))
  61.                 && (TestLine_r(0, patch->origin, patch2->origin) == CONTENTS_EMPTY)
  62. #ifdef HLRAD_HULLU
  63.                 && (!TestSegmentAgainstOpaqueList(patch->origin, patch2->origin, transparency)))
  64. #else
  65.                 && (!TestSegmentAgainstOpaqueList(patch->origin, patch2->origin)))
  66. #endif
  67.             {
  68. #ifdef HLRAD_HULLU                
  69.                 if(g_customshadow_with_bouncelight)
  70.                 {
  71.                     VectorCopy(transparency, transparency_out);
  72.                 }
  73. #endif
  74.                 return true;
  75.             }
  76.         }
  77.     }
  78.  
  79.     return false;
  80. }
  81.  
  82. //
  83. // end old vismat.c
  84. ////////////////////////////
  85.  
  86. void            MakeScalesNoVismatrix()
  87. {
  88.     char            transferfile[_MAX_PATH];
  89.  
  90.     hlassume(g_num_patches < MAX_PATCHES, assume_MAX_PATCHES);
  91.  
  92.     safe_strncpy(transferfile, g_source, _MAX_PATH);
  93.     StripExtension(transferfile);
  94.     DefaultExtension(transferfile, ".inc");
  95.  
  96.     if (!g_incremental || !readtransfers(transferfile, g_num_patches))
  97.     {
  98.         g_CheckVisBit = CheckVisBitNoVismatrix;
  99. #ifndef HLRAD_HULLU
  100.         NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);
  101. #else
  102.     if(g_rgb_transfers)
  103.         {NamedRunThreadsOn(g_num_patches, g_estimate, MakeRGBScales);}
  104.     else
  105.         {NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);}
  106. #endif
  107.  
  108.         // invert the transfers for gather vs scatter
  109. #ifndef HLRAD_HULLU
  110.         NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);
  111. #else
  112.     if(g_rgb_transfers)
  113.         {NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapRGBTransfers);}
  114.     else
  115.         {NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);}
  116. #endif
  117.         if (g_incremental)
  118.         {
  119.             writetransfers(transferfile, g_num_patches);
  120.         }
  121.         else
  122.         {
  123.             unlink(transferfile);
  124.         }
  125.         DumpTransfersMemoryUsage();
  126.     }
  127. }
  128.